{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import time\n",
    "import random\n",
    "import jsonlines\n",
    "import pandas as pd\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question11_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the highest coffee price from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        max_price = 0\n",
    "        max_currency = \"\"\n",
    "        for row_id in range(len(sub_data)):\n",
    "            if sub_data.iloc[row_id][\"High\"] > max_price:\n",
    "                max_price = sub_data.iloc[row_id][\"High\"]\n",
    "                max_currency = sub_data.iloc[row_id][\"Currency\"]\n",
    "        question = \"What was the highest coffee price from {} to {}?\".format(start_date, end_date)\n",
    "        answer = str(max_price) + ' ' + max_currency\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question12_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the lowest coffee price from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        min_price = 1000000\n",
    "        min_currency = \"\"\n",
    "        for row_id in range(len(sub_data)):\n",
    "            if sub_data.iloc[row_id][\"Low\"] < min_price:\n",
    "                min_price = sub_data.iloc[row_id][\"Low\"]\n",
    "                min_currency = sub_data.iloc[row_id][\"Currency\"]\n",
    "        question = \"What was the lowest coffee price from {} to {}?\".format(start_date, end_date)\n",
    "        answer = str(min_price) + ' ' + min_currency\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question13_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the average coffee price during the given period?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        total_price = 0\n",
    "        for row_id in range(len(sub_data)):\n",
    "            total_price += sub_data.iloc[row_id][\"Close\"]\n",
    "        avg_price = total_price / len(sub_data)\n",
    "        question = \"What was the average coffee price from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(avg_price) + ' ' + sub_data.iloc[0][\"Currency\"]\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question14_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # How much did the coffee price change from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        start_price = sub_data.iloc[0][\"Open\"]\n",
    "        end_price = sub_data.iloc[-1][\"Close\"]\n",
    "        change = end_price - start_price\n",
    "        question = \"How much did the coffee price change from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(change) + ' ' + sub_data.iloc[0][\"Currency\"]\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question15_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the percentage change in coffee price on {date} compared to the previous day?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(1, len(date_list)-1)\n",
    "        today = date_list[random_indices]\n",
    "        yesterday = date_list[random_indices-1]\n",
    "        today_data = data.loc[data[\"Date\"] == today]\n",
    "        yesterday_data = data.loc[data[\"Date\"] == yesterday]\n",
    "        today_price = today_data.iloc[0][\"Close\"]\n",
    "        yesterday_price = yesterday_data.iloc[0][\"Close\"]\n",
    "        change = today_price - yesterday_price\n",
    "        question = \"What was the percentage change in coffee price on {} compared to the previous day?\".format(today)\n",
    "        answer = \"{:.1f}\".format(change / yesterday_price * 100) + '%'\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question16_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # On which date from {start_date} to {end_date} was the difference between the highest and lowest coffee prices the greatest?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        max_diff = 0\n",
    "        max_date = \"\"\n",
    "        for row_id in range(len(sub_data)):\n",
    "            diff = sub_data.iloc[row_id][\"High\"] - sub_data.iloc[row_id][\"Low\"]\n",
    "            if diff > max_diff:\n",
    "                max_diff = diff\n",
    "                max_date = sub_data.iloc[row_id][\"Date\"]\n",
    "        question = \"On which date from {} to {} was the difference between the highest and lowest coffee prices the greatest?\".format(start_date, end_date)\n",
    "        answer = max_date\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question17_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the average daily volume of coffee traded from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        total_volume = 0\n",
    "        for row_id in range(len(sub_data)):\n",
    "            total_volume += sub_data.iloc[row_id][\"Volume\"]\n",
    "        avg_volume = total_volume / len(sub_data)\n",
    "        question = \"What was the average daily volume of coffee traded from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(avg_volume)\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question18_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # On which date from {start_date} to {end_date} did the coffee price have the highest increase compared to the previous day?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        max_change = 0\n",
    "        for row_id in range(1, len(sub_data)):\n",
    "            today = sub_data.iloc[row_id]\n",
    "            yesterday = sub_data.iloc[row_id-1]\n",
    "            today_price = today[\"Close\"]\n",
    "            yesterday_price = yesterday[\"Close\"]\n",
    "            change = today_price - yesterday_price\n",
    "            if change > max_change:\n",
    "                max_change = change\n",
    "                max_date = today[\"Date\"]\n",
    "        question = \"On which date from {} to {} did the coffee price have the highest increase compared to the previous day?\".format(start_date, end_date)\n",
    "        answer = max_date\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question19_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # How many times from {start_time} to {end_time} did the coffee price increase compared to the previous day?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        count = 0\n",
    "        for row_id in range(1, len(sub_data)):\n",
    "            today = sub_data.iloc[row_id]\n",
    "            yesterday = sub_data.iloc[row_id-1]\n",
    "            today_price = today[\"Close\"]\n",
    "            yesterday_price = yesterday[\"Close\"]\n",
    "            if today_price > yesterday_price:\n",
    "                count += 1\n",
    "        question = \"How many times from {} to {} did the coffee price increase compared to the previous day?\".format(start_date, end_date)\n",
    "        answer = str(count)\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question20_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the percentage increase in coffee price from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(0, len(date_list)-2)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        start_price = sub_data.iloc[0][\"Open\"]\n",
    "        end_price = sub_data.iloc[-1][\"Close\"]\n",
    "        change = end_price - start_price\n",
    "        question = \"What was the percentage increase in coffee price from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(change / start_price * 100) + '%'\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question21_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the coffee price range from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        start_date = date_list[0]\n",
    "        random_indices = random.randint(1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        lowest_price = 0\n",
    "        highest_price = 0\n",
    "        for row_id in range(len(sub_data)):\n",
    "            if sub_data.iloc[row_id][\"Low\"] < lowest_price:\n",
    "                lowest_price = sub_data.iloc[row_id][\"Low\"]\n",
    "            if sub_data.iloc[row_id][\"High\"] > highest_price:\n",
    "                highest_price = sub_data.iloc[row_id][\"High\"]\n",
    "        question = \"What was the coffee price range from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(highest_price - lowest_price) + ' ' + sub_data.iloc[0][\"Currency\"]\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question22_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # On how many days from {start_date} to {end_date} did the coffee price close higher than the opening price?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        start_date = date_list[0]\n",
    "        random_indices = random.randint(1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        count = 0\n",
    "        for row_id in range(len(sub_data)):\n",
    "            if sub_data.iloc[row_id][\"Close\"] > sub_data.iloc[row_id][\"Open\"]:\n",
    "                count += 1\n",
    "        question = \"On how many days from {} to {} did the coffee price close higher than the opening price?\".format(start_date, end_date)\n",
    "        answer = str(count)\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def question23_gen(data, num_questions_per_template, questions, question_id):\n",
    "    # What was the average percentage change in coffee price from {start_date} to {end_date}?\n",
    "    date_list = data[\"Date\"].unique()\n",
    "    date_list = sorted(date_list)\n",
    "    target = question_id + num_questions_per_template\n",
    "    while question_id < target:\n",
    "        random_indices = random.randint(1, len(date_list)-1)\n",
    "        start_date = date_list[random_indices]\n",
    "        random_indices2 = random.randint(random_indices+1, len(date_list)-1)\n",
    "        end_date = date_list[random_indices2]\n",
    "        sub_data = data.loc[(data[\"Date\"] >= start_date) & (data[\"Date\"] <= end_date)]\n",
    "        avg_change_rate = 0\n",
    "        for row_id in range(len(sub_data)):\n",
    "            start_price = sub_data.iloc[row_id][\"Open\"]\n",
    "            end_price = sub_data.iloc[row_id][\"Close\"]\n",
    "            change = end_price - start_price\n",
    "            avg_change_rate += change / start_price * 100\n",
    "        avg_change_rate /= len(sub_data)\n",
    "        question = \"What was the average percentage change in coffee price from {} to {}?\".format(start_date, end_date)\n",
    "        answer = \"{:.1f}\".format(avg_change_rate) + '%'\n",
    "        questions.append({\"qid\": \"hard-coffee-{:0>4d}\".format(question_id), \"question\":question, \"answer\":answer})\n",
    "        question_id += 1\n",
    "    return questions, question_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "start_time = time.time()\n",
    "file_path = \"<YOUR_OWN_PATH>/ToolQA/data/raw_data/coffee/coffee_price.csv\"\n",
    "data = pd.read_csv(file_path)\n",
    "num_questions_per_template = 10\n",
    "question_id = 0\n",
    "questions = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0000', 'question': 'What was the highest coffee price from 2009-12-23 to 2019-05-10?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0001', 'question': 'What was the highest coffee price from 2010-03-26 to 2014-05-15?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0002', 'question': 'What was the highest coffee price from 2009-04-28 to 2021-10-14?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0003', 'question': 'What was the highest coffee price from 2008-02-28 to 2020-07-08?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0004', 'question': 'What was the highest coffee price from 2004-10-13 to 2018-12-21?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0005', 'question': 'What was the highest coffee price from 2022-06-22 to 2022-08-16?', 'answer': '237.1 USD'}, {'qid': 'hard-coffee-0006', 'question': 'What was the highest coffee price from 2000-10-25 to 2012-10-17?', 'answer': '306.25 USD'}, {'qid': 'hard-coffee-0007', 'question': 'What was the highest coffee price from 2010-03-09 to 2010-07-15?', 'answer': '175.0 USD'}, {'qid': 'hard-coffee-0008', 'question': 'What was the highest coffee price from 2017-10-20 to 2020-04-23?', 'answer': '138.4 USD'}, {'qid': 'hard-coffee-0009', 'question': 'What was the highest coffee price from 2009-09-01 to 2012-06-21?', 'answer': '306.25 USD'}]\n",
      "Time taken: 3.14312481880188 for Question 11.\n"
     ]
    }
   ],
   "source": [
    "# question template 11\n",
    "questions, question_id = question11_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time taken: {} for Question 11.\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0010', 'question': 'What was the lowest coffee price from 2013-07-29 to 2018-12-04?', 'answer': '92.0 USD'}, {'qid': 'hard-coffee-0011', 'question': 'What was the lowest coffee price from 2020-03-04 to 2021-11-03?', 'answer': '92.7 USD'}, {'qid': 'hard-coffee-0012', 'question': 'What was the lowest coffee price from 2008-05-21 to 2016-06-24?', 'answer': '100.95 USD'}, {'qid': 'hard-coffee-0013', 'question': 'What was the lowest coffee price from 2002-04-25 to 2012-10-01?', 'answer': '46.0 USD'}, {'qid': 'hard-coffee-0014', 'question': 'What was the lowest coffee price from 2020-06-03 to 2022-01-20?', 'answer': '92.7 USD'}, {'qid': 'hard-coffee-0015', 'question': 'What was the lowest coffee price from 2005-07-14 to 2014-04-23?', 'answer': '87.5 USD'}, {'qid': 'hard-coffee-0016', 'question': 'What was the lowest coffee price from 2001-04-23 to 2015-12-02?', 'answer': '41.5 USD'}, {'qid': 'hard-coffee-0017', 'question': 'What was the lowest coffee price from 2014-08-19 to 2019-03-28?', 'answer': '92.0 USD'}, {'qid': 'hard-coffee-0018', 'question': 'What was the lowest coffee price from 2018-10-30 to 2021-02-11?', 'answer': '86.35 USD'}, {'qid': 'hard-coffee-0019', 'question': 'What was the lowest coffee price from 2009-11-25 to 2021-11-29?', 'answer': '86.35 USD'}]\n",
      "Time elapsed for Question 12: 6.621526479721069 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 12\n",
    "questions, question_id = question12_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 12: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0020', 'question': 'What was the average coffee price from 2018-05-22 to 2021-01-08?', 'answer': '106.7 USD'}, {'qid': 'hard-coffee-0021', 'question': 'What was the average coffee price from 2009-10-21 to 2021-10-07?', 'answer': '148.1 USD'}, {'qid': 'hard-coffee-0022', 'question': 'What was the average coffee price from 2016-10-24 to 2019-03-29?', 'answer': '122.6 USD'}, {'qid': 'hard-coffee-0023', 'question': 'What was the average coffee price from 2003-02-21 to 2010-03-16?', 'answer': '105.9 USD'}, {'qid': 'hard-coffee-0024', 'question': 'What was the average coffee price from 2001-04-19 to 2010-08-22?', 'answer': '98.1 USD'}, {'qid': 'hard-coffee-0025', 'question': 'What was the average coffee price from 2004-11-09 to 2019-10-11?', 'answer': '140.5 USD'}, {'qid': 'hard-coffee-0026', 'question': 'What was the average coffee price from 2008-12-30 to 2015-05-29?', 'answer': '168.7 USD'}, {'qid': 'hard-coffee-0027', 'question': 'What was the average coffee price from 2000-03-15 to 2007-03-16?', 'answer': '79.0 USD'}, {'qid': 'hard-coffee-0028', 'question': 'What was the average coffee price from 2002-02-20 to 2005-09-08?', 'answer': '73.8 USD'}, {'qid': 'hard-coffee-0029', 'question': 'What was the average coffee price from 2013-12-30 to 2016-02-05?', 'answer': '153.6 USD'}]\n",
      "Time elapsed for Question 13: 9.899036407470703 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 13\n",
    "questions, question_id = question13_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 13: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0030', 'question': 'How much did the coffee price change from 2017-08-16 to 2019-06-19?', 'answer': '-36.6 USD'}, {'qid': 'hard-coffee-0031', 'question': 'How much did the coffee price change from 2018-03-21 to 2022-07-25?', 'answer': '91.5 USD'}, {'qid': 'hard-coffee-0032', 'question': 'How much did the coffee price change from 2007-06-18 to 2018-09-26?', 'answer': '-16.8 USD'}, {'qid': 'hard-coffee-0033', 'question': 'How much did the coffee price change from 2019-11-21 to 2021-03-16?', 'answer': '24.5 USD'}, {'qid': 'hard-coffee-0034', 'question': 'How much did the coffee price change from 2001-12-27 to 2021-02-12?', 'answer': '74.7 USD'}, {'qid': 'hard-coffee-0035', 'question': 'How much did the coffee price change from 2014-12-21 to 2018-07-09?', 'answer': '-62.7 USD'}, {'qid': 'hard-coffee-0036', 'question': 'How much did the coffee price change from 2020-12-28 to 2022-01-21?', 'answer': '112.2 USD'}, {'qid': 'hard-coffee-0037', 'question': 'How much did the coffee price change from 2022-04-11 to 2022-07-11?', 'answer': '-14.8 USD'}, {'qid': 'hard-coffee-0038', 'question': 'How much did the coffee price change from 2004-05-27 to 2020-01-29?', 'answer': '22.2 USD'}, {'qid': 'hard-coffee-0039', 'question': 'How much did the coffee price change from 2015-09-04 to 2018-11-30?', 'answer': '-13.2 USD'}]\n",
      "Time elapsed for Question 14: 11.186464309692383 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 14\n",
    "questions, question_id = question14_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 14: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0040', 'question': 'What was the percentage change in coffee price on 2021-05-28 compared to the previous day?', 'answer': '4.5%'}, {'qid': 'hard-coffee-0041', 'question': 'What was the percentage change in coffee price on 2019-05-30 compared to the previous day?', 'answer': '2.9%'}, {'qid': 'hard-coffee-0042', 'question': 'What was the percentage change in coffee price on 2018-07-06 compared to the previous day?', 'answer': '4.7%'}, {'qid': 'hard-coffee-0043', 'question': 'What was the percentage change in coffee price on 2005-01-07 compared to the previous day?', 'answer': '-0.6%'}, {'qid': 'hard-coffee-0044', 'question': 'What was the percentage change in coffee price on 2003-07-11 compared to the previous day?', 'answer': '0.3%'}, {'qid': 'hard-coffee-0045', 'question': 'What was the percentage change in coffee price on 2018-01-08 compared to the previous day?', 'answer': '-2.6%'}, {'qid': 'hard-coffee-0046', 'question': 'What was the percentage change in coffee price on 2001-11-30 compared to the previous day?', 'answer': '1.4%'}, {'qid': 'hard-coffee-0047', 'question': 'What was the percentage change in coffee price on 2005-11-09 compared to the previous day?', 'answer': '-0.9%'}, {'qid': 'hard-coffee-0048', 'question': 'What was the percentage change in coffee price on 2000-04-14 compared to the previous day?', 'answer': '-2.2%'}, {'qid': 'hard-coffee-0049', 'question': 'What was the percentage change in coffee price on 2001-03-05 compared to the previous day?', 'answer': '0.6%'}]\n",
      "Time elapsed for Question 15: 13.521226167678833 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 15\n",
    "questions, question_id = question15_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 15: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0050', 'question': 'On which date from 2016-10-14 to 2019-11-05 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2016-11-10'}, {'qid': 'hard-coffee-0051', 'question': 'On which date from 2004-02-02 to 2020-02-06 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-02-19'}, {'qid': 'hard-coffee-0052', 'question': 'On which date from 2012-09-25 to 2019-07-15 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-02-19'}, {'qid': 'hard-coffee-0053', 'question': 'On which date from 2012-05-11 to 2017-07-17 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-02-19'}, {'qid': 'hard-coffee-0054', 'question': 'On which date from 2017-10-27 to 2018-11-08 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2018-10-29'}, {'qid': 'hard-coffee-0055', 'question': 'On which date from 2005-04-21 to 2020-08-12 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-02-19'}, {'qid': 'hard-coffee-0056', 'question': 'On which date from 2014-05-30 to 2020-09-16 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-10-06'}, {'qid': 'hard-coffee-0057', 'question': 'On which date from 2015-05-01 to 2020-01-03 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2016-06-09'}, {'qid': 'hard-coffee-0058', 'question': 'On which date from 2021-11-04 to 2021-11-30 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2021-11-29'}, {'qid': 'hard-coffee-0059', 'question': 'On which date from 2014-04-16 to 2018-03-05 was the difference between the highest and lowest coffee prices the greatest?', 'answer': '2014-10-06'}]\n",
      "Time elapsed for Question 16: 17.189119338989258 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 16\n",
    "questions, question_id = question16_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 16: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0060', 'question': 'What was the average daily volume of coffee traded from 2019-09-11 to 2022-01-26?', 'answer': '13003.8'}, {'qid': 'hard-coffee-0061', 'question': 'What was the average daily volume of coffee traded from 2002-03-28 to 2015-06-09?', 'answer': '7358.8'}, {'qid': 'hard-coffee-0062', 'question': 'What was the average daily volume of coffee traded from 2007-08-02 to 2009-08-26?', 'answer': '7455.1'}, {'qid': 'hard-coffee-0063', 'question': 'What was the average daily volume of coffee traded from 2006-04-20 to 2019-03-06?', 'answer': '9322.4'}, {'qid': 'hard-coffee-0064', 'question': 'What was the average daily volume of coffee traded from 2013-05-29 to 2013-09-19?', 'answer': '8729.9'}, {'qid': 'hard-coffee-0065', 'question': 'What was the average daily volume of coffee traded from 2018-09-06 to 2021-05-24?', 'answer': '14088.0'}, {'qid': 'hard-coffee-0066', 'question': 'What was the average daily volume of coffee traded from 2008-09-11 to 2014-07-30?', 'answer': '7812.2'}, {'qid': 'hard-coffee-0067', 'question': 'What was the average daily volume of coffee traded from 2011-10-25 to 2013-12-19?', 'answer': '8534.1'}, {'qid': 'hard-coffee-0068', 'question': 'What was the average daily volume of coffee traded from 2002-12-02 to 2003-09-04?', 'answer': '4381.5'}, {'qid': 'hard-coffee-0069', 'question': 'What was the average daily volume of coffee traded from 2020-08-24 to 2021-05-12?', 'answer': '11236.8'}]\n",
      "Time elapsed for Question 17: 19.36780595779419 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 17\n",
    "questions, question_id = question17_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 17: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0070', 'question': 'On which date from 2017-07-05 to 2021-11-09 did the coffee price have the highest increase compared to the previous day?', 'answer': '2021-07-26'}, {'qid': 'hard-coffee-0071', 'question': 'On which date from 2019-05-03 to 2021-10-25 did the coffee price have the highest increase compared to the previous day?', 'answer': '2021-07-26'}, {'qid': 'hard-coffee-0072', 'question': 'On which date from 2016-01-26 to 2022-02-23 did the coffee price have the highest increase compared to the previous day?', 'answer': '2021-07-26'}, {'qid': 'hard-coffee-0073', 'question': 'On which date from 2016-03-02 to 2019-07-16 did the coffee price have the highest increase compared to the previous day?', 'answer': '2016-06-08'}, {'qid': 'hard-coffee-0074', 'question': 'On which date from 2019-10-15 to 2022-04-05 did the coffee price have the highest increase compared to the previous day?', 'answer': '2021-07-26'}, {'qid': 'hard-coffee-0075', 'question': 'On which date from 2022-02-18 to 2022-06-08 did the coffee price have the highest increase compared to the previous day?', 'answer': '2022-05-11'}, {'qid': 'hard-coffee-0076', 'question': 'On which date from 2015-09-28 to 2018-12-20 did the coffee price have the highest increase compared to the previous day?', 'answer': '2016-06-08'}, {'qid': 'hard-coffee-0077', 'question': 'On which date from 2000-01-11 to 2020-08-21 did the coffee price have the highest increase compared to the previous day?', 'answer': '2014-02-19'}, {'qid': 'hard-coffee-0078', 'question': 'On which date from 2014-07-15 to 2021-10-05 did the coffee price have the highest increase compared to the previous day?', 'answer': '2021-07-26'}, {'qid': 'hard-coffee-0079', 'question': 'On which date from 2004-05-06 to 2010-01-25 did the coffee price have the highest increase compared to the previous day?', 'answer': '2004-11-15'}]\n",
      "Time elapsed for Question 18: 22.370015382766724 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 18\n",
    "questions, question_id = question18_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 18: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0080', 'question': 'How many times from 2009-06-26 to 2021-03-16 did the coffee price increase compared to the previous day?', 'answer': '1491'}, {'qid': 'hard-coffee-0081', 'question': 'How many times from 2009-07-20 to 2011-01-26 did the coffee price increase compared to the previous day?', 'answer': '221'}, {'qid': 'hard-coffee-0082', 'question': 'How many times from 2012-10-10 to 2019-06-27 did the coffee price increase compared to the previous day?', 'answer': '835'}, {'qid': 'hard-coffee-0083', 'question': 'How many times from 2012-11-30 to 2014-03-24 did the coffee price increase compared to the previous day?', 'answer': '165'}, {'qid': 'hard-coffee-0084', 'question': 'How many times from 2012-06-07 to 2017-11-16 did the coffee price increase compared to the previous day?', 'answer': '688'}, {'qid': 'hard-coffee-0085', 'question': 'How many times from 2009-12-13 to 2020-05-05 did the coffee price increase compared to the previous day?', 'answer': '1319'}, {'qid': 'hard-coffee-0086', 'question': 'How many times from 2002-10-18 to 2014-11-30 did the coffee price increase compared to the previous day?', 'answer': '1561'}, {'qid': 'hard-coffee-0087', 'question': 'How many times from 2000-02-25 to 2004-03-26 did the coffee price increase compared to the previous day?', 'answer': '473'}, {'qid': 'hard-coffee-0088', 'question': 'How many times from 2009-08-05 to 2012-02-01 did the coffee price increase compared to the previous day?', 'answer': '343'}, {'qid': 'hard-coffee-0089', 'question': 'How many times from 2021-11-17 to 2022-07-21 did the coffee price increase compared to the previous day?', 'answer': '78'}]\n",
      "Time elapsed for Question 19: 25.534488439559937 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 19\n",
    "questions, question_id = question19_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 19: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0090', 'question': 'What was the percentage increase in coffee price from 2017-10-16 to 2022-06-23?', 'answer': '81.6%'}, {'qid': 'hard-coffee-0091', 'question': 'What was the percentage increase in coffee price from 2017-04-25 to 2020-07-24?', 'answer': '-16.3%'}, {'qid': 'hard-coffee-0092', 'question': 'What was the percentage increase in coffee price from 2016-05-26 to 2021-11-01?', 'answer': '71.2%'}, {'qid': 'hard-coffee-0093', 'question': 'What was the percentage increase in coffee price from 2022-03-28 to 2022-05-02?', 'answer': '-2.4%'}, {'qid': 'hard-coffee-0094', 'question': 'What was the percentage increase in coffee price from 2013-11-14 to 2015-09-17?', 'answer': '10.1%'}, {'qid': 'hard-coffee-0095', 'question': 'What was the percentage increase in coffee price from 2012-10-12 to 2014-04-08?', 'answer': '22.0%'}, {'qid': 'hard-coffee-0096', 'question': 'What was the percentage increase in coffee price from 2012-03-02 to 2014-09-26?', 'answer': '-8.3%'}, {'qid': 'hard-coffee-0097', 'question': 'What was the percentage increase in coffee price from 2011-08-11 to 2016-09-26?', 'answer': '-34.7%'}, {'qid': 'hard-coffee-0098', 'question': 'What was the percentage increase in coffee price from 2010-10-14 to 2012-01-20?', 'answer': '21.0%'}, {'qid': 'hard-coffee-0099', 'question': 'What was the percentage increase in coffee price from 2004-10-19 to 2014-12-22?', 'answer': '134.7%'}]\n",
      "Time elapsed for Question 20: 25.734045028686523 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 20\n",
    "questions, question_id = question20_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 20: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0100', 'question': 'What was the coffee price range from 2000-01-03 to 2014-03-24?', 'answer': '306.2 USD'}, {'qid': 'hard-coffee-0101', 'question': 'What was the coffee price range from 2000-01-03 to 2020-05-19?', 'answer': '306.2 USD'}, {'qid': 'hard-coffee-0102', 'question': 'What was the coffee price range from 2000-01-03 to 2002-05-16?', 'answer': '126.0 USD'}, {'qid': 'hard-coffee-0103', 'question': 'What was the coffee price range from 2000-01-03 to 2020-10-07?', 'answer': '306.2 USD'}, {'qid': 'hard-coffee-0104', 'question': 'What was the coffee price range from 2000-01-03 to 2000-12-05?', 'answer': '126.0 USD'}, {'qid': 'hard-coffee-0105', 'question': 'What was the coffee price range from 2000-01-03 to 2011-07-13?', 'answer': '306.2 USD'}, {'qid': 'hard-coffee-0106', 'question': 'What was the coffee price range from 2000-01-03 to 2011-03-09?', 'answer': '294.7 USD'}, {'qid': 'hard-coffee-0107', 'question': 'What was the coffee price range from 2000-01-03 to 2000-03-28?', 'answer': '126.0 USD'}, {'qid': 'hard-coffee-0108', 'question': 'What was the coffee price range from 2000-01-03 to 2012-04-04?', 'answer': '306.2 USD'}, {'qid': 'hard-coffee-0109', 'question': 'What was the coffee price range from 2000-01-03 to 2019-03-01?', 'answer': '306.2 USD'}]\n",
      "Time elapsed for Question 21: 32.440794706344604 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 21\n",
    "questions, question_id = question21_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 21: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0110', 'question': 'On how many days from 2000-01-03 to 2017-07-27 did the coffee price close higher than the opening price?', 'answer': '2126'}, {'qid': 'hard-coffee-0111', 'question': 'On how many days from 2000-01-03 to 2009-08-07 did the coffee price close higher than the opening price?', 'answer': '1224'}, {'qid': 'hard-coffee-0112', 'question': 'On how many days from 2000-01-03 to 2012-07-23 did the coffee price close higher than the opening price?', 'answer': '1564'}, {'qid': 'hard-coffee-0113', 'question': 'On how many days from 2000-01-03 to 2007-04-19 did the coffee price close higher than the opening price?', 'answer': '943'}, {'qid': 'hard-coffee-0114', 'question': 'On how many days from 2000-01-03 to 2012-12-10 did the coffee price close higher than the opening price?', 'answer': '1603'}, {'qid': 'hard-coffee-0115', 'question': 'On how many days from 2000-01-03 to 2018-02-26 did the coffee price close higher than the opening price?', 'answer': '2188'}, {'qid': 'hard-coffee-0116', 'question': 'On how many days from 2000-01-03 to 2005-05-31 did the coffee price close higher than the opening price?', 'answer': '694'}, {'qid': 'hard-coffee-0117', 'question': 'On how many days from 2000-01-03 to 2013-11-11 did the coffee price close higher than the opening price?', 'answer': '1706'}, {'qid': 'hard-coffee-0118', 'question': 'On how many days from 2000-01-03 to 2016-12-14 did the coffee price close higher than the opening price?', 'answer': '2064'}, {'qid': 'hard-coffee-0119', 'question': 'On how many days from 2000-01-03 to 2007-11-06 did the coffee price close higher than the opening price?', 'answer': '1018'}]\n",
      "Time elapsed for Question 22: 37.60163998603821 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 22\n",
    "questions, question_id = question22_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 22: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'qid': 'hard-coffee-0120', 'question': 'What was the average percentage change in coffee price from 2017-06-02 to 2020-10-19?', 'answer': '-0.2%'}, {'qid': 'hard-coffee-0121', 'question': 'What was the average percentage change in coffee price from 2000-04-27 to 2011-09-14?', 'answer': '0.1%'}, {'qid': 'hard-coffee-0122', 'question': 'What was the average percentage change in coffee price from 2016-04-19 to 2021-10-14?', 'answer': '-0.2%'}, {'qid': 'hard-coffee-0123', 'question': 'What was the average percentage change in coffee price from 2009-08-13 to 2011-10-05?', 'answer': '-0.0%'}, {'qid': 'hard-coffee-0124', 'question': 'What was the average percentage change in coffee price from 2008-09-08 to 2022-01-31?', 'answer': '-0.1%'}, {'qid': 'hard-coffee-0125', 'question': 'What was the average percentage change in coffee price from 2007-01-31 to 2018-10-16?', 'answer': '-0.1%'}, {'qid': 'hard-coffee-0126', 'question': 'What was the average percentage change in coffee price from 2003-07-18 to 2012-12-14?', 'answer': '0.0%'}, {'qid': 'hard-coffee-0127', 'question': 'What was the average percentage change in coffee price from 2015-04-10 to 2017-04-11?', 'answer': '-0.1%'}, {'qid': 'hard-coffee-0128', 'question': 'What was the average percentage change in coffee price from 2019-08-08 to 2020-06-11?', 'answer': '-0.3%'}, {'qid': 'hard-coffee-0129', 'question': 'What was the average percentage change in coffee price from 2022-02-17 to 2022-06-08?', 'answer': '-0.1%'}]\n",
      "Time elapsed for Question 23: 42.17541217803955 seconds\n"
     ]
    }
   ],
   "source": [
    "# question template 23\n",
    "questions, question_id = question23_gen(data, num_questions_per_template, questions, question_id)\n",
    "end_time = time.time()\n",
    "print(questions[-10:])\n",
    "print(\"Time elapsed for Question 23: {} seconds\".format(end_time - start_time))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "with jsonlines.open('/<YOUR_OWN_PATH>/ToolQA/data/questions/hard/coffee-hard.jsonl', mode='w') as writer:\n",
    "    for row in questions:\n",
    "        writer.write(row)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
